package com.jmm.api.config;

import lombok.Data;
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * The type Social config.
 */
@Configuration
@ConfigurationProperties(prefix = "yogo.social")
@Data
public class SocialConfig {
    private String wechatAppId;
    private String wechatAppSecret;

    /**
     * Wx config provider wx mp config storage.
     *
     * @return the wx mp config storage
     */
    @Bean
    public WxMpConfigStorage wxConfigProvider(){
        WxMpInMemoryConfigStorage wxMpInMemoryConfigStorage = new WxMpInMemoryConfigStorage();
        wxMpInMemoryConfigStorage.setAppId(wechatAppId);
        wxMpInMemoryConfigStorage.setSecret(wechatAppSecret);
        return wxMpInMemoryConfigStorage;
    }

    /**
     * Wx mp service wx mp service.
     *
     * @param wxConfigProvider the wx config provider
     * @return the wx mp service
     */
    @Bean
    public WxMpService wxMpService(WxMpConfigStorage wxConfigProvider){
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxConfigProvider);
        return wxMpService;
    }
}
